<%@page import="com.shsh.safemanage.util.RequestUtil"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.shsh.safemanage.action.PostcheckReportAction"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.model.Department1"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.PostcheckMonthCheckSummaryReport"%>
<%@page import="com.shsh.safemanage.model.PostcheckMonthCheckSummaryCell"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%
{
	Integer year = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_YEAR, 0);
	Integer month = RequestUtil.getParameter(request, Constants.REQUEST_PARAMETER_MONTH, 0);
	
	User sessionUser = (User)session.getAttribute(Constants.SESSION_USER);
	
	PostcheckReportAction reportAction = ActionCreator.createPostcheckReportAction();
	PostcheckMonthCheckSummaryReport reportTable = null;
	boolean isSuccess = reportAction.generateMonthCheckSummaryReport(request);
	if(isSuccess) {
	 	reportTable = (PostcheckMonthCheckSummaryReport)request.getAttribute(Constants.REQUEST_ATTRIBUTE_POSTCHECK_MONTH_CHECK_SUMMARY_REPORT);
	}
	
	List<PostCheck> postcheckList = reportTable.getPostcheckList();
	List<Department1> depart1List = reportTable.getDepart1List();
	Map<Long, Map<Long, PostcheckMonthCheckSummaryCell>> cellMap = reportTable.getCellMap();
	
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; 岗检汇总统计 &gt;&gt;上海高桥分公司公司<%=month%>月岗检考核汇总表
</div>
<div class="tt">《上海高桥分公司<%=year %>年<%=month %>月岗检考核汇总表》</div>
<div class="content" style="height:410px;">
	<div style="margin-left: 10px">
	<span id="monthSelectSpan" style="margin-left: 10px;float:left;">	
	<%@include file="/postcheck_select/month_select_section2.jsp" %>
	</span>
	</div>
	<table border="1" width="97%" style="align:center; margin-left: 6px">
		<tr>
			<td colspan="2" style="text-align:center; height:70px;" class="td3">
			部门
			</td>
			<% for(Department1 depart1 : depart1List) {%>
			<td style="text-align:center; width:50px;" class="td3">
				<a href="javascript:" onclick="openDepartReport(<%=depart1.getId()%>)"><%=depart1.getId().equals(0l)?"合计":depart1.getDepartmentName() %></a>
			</td>
			<%} %>
		</tr>
		<% 
		for(int i=0;i<postcheckList.size()-1;i++) {
			PostCheck postcheck = postcheckList.get(i);
		%>
		<tr>
			<td rowspan="2" style="text-align:center;width:6%;" class="td3">
				<%=postcheck.getId().equals(0l)?"合计":postcheck.getCheckName() %>
			</td>
			<td style="text-align:center;width:8%;" class="td3">
				问题数（个）
			</td>			
			<% for(Department1 depart1 : depart1List) {
				Map<Long, PostcheckMonthCheckSummaryCell> map = cellMap.get(postcheck.getId());
				if (map == null ){
					map = new HashMap<Long, PostcheckMonthCheckSummaryCell>(); 
				}
				PostcheckMonthCheckSummaryCell cell = map.get(depart1.getId());				
			%>
			<td style="text-align:center;  height:20px;">
				<%=cell != null && cell.getProblemCount()!=null?cell.getProblemCount():"&nbsp;" %>
			</td>
			<% 
			} %>
		</tr>
		<tr>
			<td style="text-align:center;" class="td3">
				扣分数（分）
			</td>		
			<% for(Department1 depart1 : depart1List) {
				Map<Long, PostcheckMonthCheckSummaryCell> map = cellMap.get(postcheck.getId());
				if (map == null ){
					map = new HashMap<Long, PostcheckMonthCheckSummaryCell>(); 
				}
				PostcheckMonthCheckSummaryCell cell = map.get(depart1.getId());				
			%>
			<td style="text-align:center; height:20px;">
				<%=cell != null && cell.getGradeSum()!=null?Util.formatGrade(cell.getGradeSum()):"&nbsp;" %>
			</td>
			<% 
			} 
			%>			
		</tr>
		<%} %>
		<%
		PostCheck postcheck = postcheckList.get(postcheckList.size()-1);
		%>

		<tr>
			<td rowspan="3" style="text-align:center;" class="td3">
				<%=postcheck.getId().equals(0l)?"合计":postcheck.getCheckName() %>
			</td>
			<td style="text-align:center;" class="td3">
				问题数（个）
			</td>			
			<% for(Department1 depart1 : depart1List) {
				Map<Long, PostcheckMonthCheckSummaryCell> map = cellMap.get(postcheck.getId());
				if (map == null ){
					map = new HashMap<Long, PostcheckMonthCheckSummaryCell>(); 
				}
				PostcheckMonthCheckSummaryCell cell = map.get(depart1.getId());				
			%>
			<td style="text-align:center;  height:20px;">
				<%=cell != null && cell.getProblemCount()!=null?cell.getProblemCount():"&nbsp;" %>
			</td>
			<% 
			} %>
		</tr>
		<tr>
			<td style="text-align:center;" class="td3">
				扣分数（分）
			</td>		
			<% for(Department1 depart1 : depart1List) {
				Map<Long, PostcheckMonthCheckSummaryCell> map = cellMap.get(postcheck.getId());
				if (map == null ){
					map = new HashMap<Long, PostcheckMonthCheckSummaryCell>(); 
				}
				PostcheckMonthCheckSummaryCell cell = map.get(depart1.getId());				
			%>
			<td style="text-align:center; height:20px;">
				<%=cell != null && cell.getGradeSum()!=null?Util.formatGrade(cell.getGradeSum()):"&nbsp;" %>
			</td>
			<% 
			} 
			%>			
		</tr>
		<tr>
			<td style="text-align:center;" class="td3">
				扣款金额（元）
			</td>		
			<% for(Department1 depart1 : depart1List) {
				Map<Long, PostcheckMonthCheckSummaryCell> map = cellMap.get(postcheck.getId());
				if (map == null ){
					map = new HashMap<Long, PostcheckMonthCheckSummaryCell>(); 
				}
				PostcheckMonthCheckSummaryCell cell = map.get(depart1.getId());				
			%>
			<td style="text-align:center; height:20px;">
				<%=cell != null && cell.getGradeSum()!=null?Util.formatGrade(cell.getGradeSum()*100):"&nbsp;" %>
			</td>
			<% 
			} 
			%>			
		</tr>
		<%
		%>
	</table>
</div>
<script type="text/javascript">
function changeReport(){
	var year = getElementValueByID('year');
	var month = getElementValueByID('month');
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/month_check_summary_report.jsp', 
			'mainContentDiv', 
			{
				year: year, 
				month: month 
			}, 
			true
	);
}
function selectYear(){
	changeReport();
}

function selectMonth(){
	changeReport();
}

function openDepartReport(depart1ID){
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/depart_month_check_summary_report.jsp', 
			'mainContentDiv', 
			{
				year: <%=year%>, 
				month: <%=month%>, 
				depart1ID: depart1ID,
				fromPage: 'monthCheckSummaryReport'
			}, 
			true
		);
}
</script>
<%
}
%>